package com.example.demo.blog;

import com.example.demo.model.Shout;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 豆腐干Sama on 2018/5/18.
 */
@Controller
public class MarcoController {
    @MessageMapping("/welcome/{channelId}")//1
    @SendTo("/topic/getResponse/{channelId}")//2
    public Shout say(@DestinationVariable String channelId, Shout message) throws Exception {
        System.out.println("typeId: " + channelId);
        return new Shout("Welcome, " + message.getMessage() + "!");
    }
    @SubscribeMapping({"/marco/{channelId}"})
    public List<Shout> sub(@DestinationVariable String channelId) {
        System.out.println("channelId : " + channelId);
        System.out.println("订阅通道");
        Shout shout1 = new Shout("m1");
        Shout shout2 = new Shout("m2");
        Shout shout3 = new Shout("m3");
        List<Shout> result = new ArrayList<>();
        result.add(shout1);
        result.add(shout2);
        result.add(shout3);
        return result;
    }

}
